package com.cdfahe.gms.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cdfahe.common.Constants;
import com.cdfahe.common.util.page.ResultFilter;
import com.cdfahe.gms.mybatis.entity.News;
import com.cdfahe.gms.service.INewsService;

/**
 * 新闻消息控制器
 * @author Donzell
 * @version 1.0
 */
@Controller("newsController")
public class NewsController {
	
	@Autowired
	private INewsService newsService;
	
	@RequestMapping(value = "/getnews")
    public String getStaticPage(Model model,HttpServletRequest request) {
		News  news = newsService.getNewsById(Integer.parseInt(request.getParameter("newsid")));
		model.addAttribute("newstitle", news.getName());
		model.addAttribute("newscontent", news.getContent());
		model.addAttribute("categoryid", news.getCategoryid());
		model.addAttribute("newstypename", Constants.NEWS_TYPE_MAP.get(news.getCategoryid().toString()));
		return "news/news";
    }
	
	 @RequestMapping(value = "/listnews")
	 public String shownewsbycategory(@ModelAttribute ResultFilter<News> rf, HttpServletRequest request,Model model) {
		String categoty =  request.getParameter("categoty");
		newsService.listNews(rf,Integer.parseInt(categoty),10);
		model.addAttribute("newstypename", Constants.NEWS_TYPE_MAP.get(categoty));
		model.addAttribute("rf", rf);
		model.addAttribute("categoty", categoty);
		 
		 
//		String percatid =  request.getParameter("percatid");
//		String page =  request.getParameter("page");
//		int pagenum = 1;
//		int pagesize = 30;
//		if (page != null && !"".equals(page)) {
//			pagenum = Integer.parseInt(page);
//		}
//		List<News> allnews = newsService.selectNewsByPageAndType(Integer.parseInt(percatid),pagenum,pagesize);
//		model.addAttribute("allnews", allnews);
//		model.addAttribute("category", percatid);
		return "news/newslist";
	 }
	 
	 
}
